/*
 * $Log: ResourceDaoImpl.java,v $
 * Revision 1.1  2012/04/13 08:40:24  guor
 * *** empty log message ***
 *
 */
package com.xlcszsgc.module.modules.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.xlcszsgc.core.basedao.base.IBaseDao;
import com.xlcszsgc.module.modules.dao.IResourceDao;
import com.xlcszsgc.module.modules.dao.require.ResourceRequire;
import com.xlcszsgc.module.modules.service.bo.ResourceCondition;
 
/**
 * Title: ResourceDaoImpl<br>
 * Description: ��ԴDAO�ӿ�ʵ��<br>
 * Company: ORCHIS<br>
 * Copyright @ 2011 ORCHIS .All rights reserved.<br>
 * @author FanKY
 * @createDate Sep 9, 2011
 * @version $Revision: 1.1 $
 */
@Repository(value = "com.xlcszsgc.module.modules.dao.impl.ResourceDaoImpl")
public class ResourceDaoImpl implements IResourceDao {
	// ��ʼ��baseDao
	@Resource(name = "com.xlcszsgc.core.basedao.base.impl.BaseDao")
	private IBaseDao baseDao;
	// ��ʼ��Hqlƴװ��
	@Resource(name = "com.xlcszsgc.module.modules.dao.require.ResourceRequire")
	private ResourceRequire resourceRequire;

	/**
	 * �����˵���Դ
	 * 
	 * @param resource
	 * @throws Exception
	 * @author FanKY
	 * @date Sep 13, 2011
	 */
	@Override
	public String addResource(
			com.xlcszsgc.module.modules.service.bo.Resource resource)
			throws Exception {
		baseDao.addEntity(resource);
		return "succeed";
	}

	/**
	 * ���ID�����������ϻ�������Դ
	 * 
	 * @param condition
	 * @throws Exception
	 * @author FanKY
	 * @date Sep 13, 2011
	 */
	@Override
	public void discardOrReuseResource(ResourceCondition condition)
			throws Exception {
		Session session = baseDao.getHibernateSession();
		String updateHql = resourceRequire.discardOrReuseResourceHql(condition);
		Query query = session.createQuery(updateHql);
		condition.setQuery(query);
		resourceRequire.discardOrReuseResourceParameter(condition);
		query.executeUpdate();
	}

	/**
	 * ���ID��ѯ�˵���Դ��Ϣ
	 * 
	 * @param condition
	 * @return ���ID��ѯ�˵���Դ��Ϣ������com.xlcszsgc.module.modules.service.bo.Resource�������
	 * @throws Exception
	 * @author FanKY
	 * @date Sep 13, 2011
	 */
	@Override
	public com.xlcszsgc.module.modules.service.bo.Resource getResource(
			ResourceCondition condition) throws Exception {
		return (com.xlcszsgc.module.modules.service.bo.Resource) baseDao
				.findObject(
						com.xlcszsgc.module.modules.service.bo.Resource.class,
						new Integer(condition.getQueryResourceId()));
	}

	/**
	 * ���²˵���Դ
	 * 
	 * @param resource
	 * @throws Exception
	 * @author FanKY
	 * @date Sep 13, 2011
	 */
	@Override
	public void updateResource(
			com.xlcszsgc.module.modules.service.bo.Resource resource)
			throws Exception {
		baseDao.updateEntityByPK(resource);
	}

	/**
	 * ��Դ�˵����ϲ�ѯ
	 * 
	 * @param condition
	 * @return ��Դ�˵����ϲ�ѯ������com.xlcszsgc.module.modules.service.bo.Resource����List
	 * @throws Exception
	 * @author FanKY
	 * @date Sep 13, 2011
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<com.xlcszsgc.module.modules.service.bo.Resource> listResource(
			ResourceCondition condition) throws Exception {
		Session session = baseDao.getHibernateSession();
		Query query = session.createQuery(resourceRequire
				.listResourceHql(condition));
		condition.setQuery(query);
		resourceRequire.listResourceParameter(condition);
		List<com.xlcszsgc.module.modules.service.bo.Resource> list = (List<com.xlcszsgc.module.modules.service.bo.Resource>) baseDao
				.findCollectionWithPage(condition);
		return list;
	}

	/**
	 * ��÷�ҳ��Ϣ
	 * 
	 * @param condition
	 * @return ��÷�ҳ��Ϣ������Long���ͽ��
	 * @throws Exception
	 * @author FanKY
	 * @date Sep 14, 2011
	 */
	@Override
	public Long findCount(ResourceCondition condition) throws Exception {
		Long result = null;
		Session session = baseDao.getHibernateSession();
		Query query = session.createQuery(resourceRequire
				.countResourceLongHql(condition));
		condition.setQuery(query);
		resourceRequire.listResourceParameter(condition);
		result = baseDao.countCollection(condition);
		return result;
	}
}
